
            
class CabinetController {
    def index = { redirect(action:list,params:params) }

    def list = {
        [ cabinetList: Cabinet.list( params ) ]
    }

    def show = {
        [ cabinet : Cabinet.get( params.id ) ]
    }

    def delete = {
        def cabinet = Cabinet.get( params.id )
        if(cabinet) {
            cabinet.delete()
            flash.message = "Cabinet ${params.id} deleted."
            redirect(action:list)
        }
        else {
            flash.message = "Cabinet not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def cabinet = Cabinet.get( params.id )

        if(!cabinet) {
                flash.message = "Cabinet not found with id ${params.id}"
                redirect(action:list)
        }
        else {
            return [ cabinet : cabinet ]
        }
    }

    def update = {
        def cabinet = Cabinet.get( params.id )
        if(cabinet) {
             cabinet.properties = params
            if(cabinet.save()) {
                redirect(action:show,id:cabinet.id)
            }
            else {
                render(view:'edit',model:[cabinet:cabinet])
            }
        }
        else {
            flash.message = "Cabinet not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def cabinet = new Cabinet()
        cabinet.properties = params
        return ['cabinet':cabinet]
    }

    def save = {
        def cabinet = new Cabinet()
        cabinet.properties = params
        if(cabinet.save()) {
            redirect(action:show,id:cabinet.id)
        }
        else {
            render(view:'create',model:[cabinet:cabinet])
        }
    }

}